package com.swiot.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.swiot.common.annotation.Log;
import com.swiot.common.core.controller.BaseController;
import com.swiot.common.core.domain.AjaxResult;
import com.swiot.common.enums.BusinessType;
import com.swiot.biz.domain.RuleDetail;
import com.swiot.biz.service.IRuleDetailService;
import com.swiot.common.utils.poi.ExcelUtil;
import com.swiot.common.core.page.TableDataInfo;

/**
 * 规则明细Controller
 * 
 * @author kingdom
 * @date 2025-08-25
 */
@RestController
@RequestMapping("/biz/detail")
public class RuleDetailController extends BaseController
{
    @Autowired
    private IRuleDetailService ruleDetailService;

    /**
     * 查询规则明细列表
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(RuleDetail ruleDetail)
    {
        startPage();
        List<RuleDetail> list = ruleDetailService.selectRuleDetailList(ruleDetail);
        return getDataTable(list);
    }

    /**
     * 导出规则明细列表
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:export')")
    @Log(title = "规则明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RuleDetail ruleDetail)
    {
        List<RuleDetail> list = ruleDetailService.selectRuleDetailList(ruleDetail);
        ExcelUtil<RuleDetail> util = new ExcelUtil<RuleDetail>(RuleDetail.class);
        util.exportExcel(response, list, "规则明细数据");
    }

    /**
     * 获取规则明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ruleDetailService.selectRuleDetailById(id));
    }

    /**
     * 新增规则明细
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:add')")
    @Log(title = "规则明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RuleDetail ruleDetail)
    {
        return toAjax(ruleDetailService.insertRuleDetail(ruleDetail));
    }

    /**
     * 修改规则明细
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:edit')")
    @Log(title = "规则明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RuleDetail ruleDetail)
    {
        return toAjax(ruleDetailService.updateRuleDetail(ruleDetail));
    }

    /**
     * 删除规则明细
     */
    @PreAuthorize("@ss.hasPermi('biz:detail:remove')")
    @Log(title = "规则明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ruleDetailService.deleteRuleDetailByIds(ids));
    }
}
